$(function () {
  var mail  = /^[A-Za-zd0-9]+([-_.][A-Za-zd]+)*@([A-Za-zd]+[-.])+[A-Za-zd]{2,5}$/;
  var phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;//手机号正则
  $("#email").blur(function () {
    var email = $(this).val();
    if (mail.test(email)) {
      $.ajax({
        type: "POST",
        url: "/email",
        data: {
          "email":email
        },
        dataType:"json",
        success: function(result){
          if (result) {
            showMsg('此邮箱可以使用！','top','successful');
          }else{
            showMsg('此邮箱已存在！','top','error');
          }
        },
        error:function (xml) {
          console.log(0);
        }
      });
    }else {
      showMsg('邮箱格式不正确！','top','error');
    }
  })
  $("#phone").blur(function () {
    var phone = $(this).val();
    if(phoneReg.test(phone)){
      $.ajax({
        type: "POST",
        url: "/phone",
        data: {
          "phone":phone
        },
        dataType:"json",
        success: function(result){
          if (result) {
            showMsg('此手机号可以使用！','top','successful');
          }else{
            showMsg('此手机号已存在！','top','error');
          }
        },
        error:function (xml) {
          console.log(0);
        }
      });
    }else{
      showMsg('请输入正确的手机格式！','top','error');
    }
  })
})
